package model

import (
	"service/basic/config"
	"time"
)

type Reservation struct {
	Id        uint      `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    uint      `gorm:"column:user_id;type:int UNSIGNED;comment:患者id;not null;" json:"user_id"`                               // 患者id
	DockerId  uint      `gorm:"column:docker_id;type:int UNSIGNED;comment:医生id;not null;" json:"docker_id"`                           // 医生id
	StartTime time.Time `gorm:"column:start_time;type:datetime;comment:预约时间;not null;default:CURRENT_TIMESTAMP;" json:"start_time"` // 预约时间
	Status    uint      `gorm:"column:status;type:int UNSIGNED;comment:预约状态：1已预约 2已取消;not null;default:1;" json:"status"`     // 预约状态：1已预约 2已取消
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (r *Reservation) TableName() string {
	return "reservation"
}

// 查找用户预约信息
func (r *Reservation) GetRecordUserId() error {
	return config.DB.Where("user_id = ?", r.UserId).Limit(1).Find(&r).Error
}

// 添加预约信息
func (r *Reservation) Create() error {
	return config.DB.Create(&r).Error
}
